package cc.smarnet.caihou.util;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;

import cc.smarnet.caihou.App;
import cc.smarnet.caihou.R;
import cc.smarnet.caihou.phone.MainPageActivity;
import cc.smarnet.caihou.phone.scanout.ScanOutActivity;

/**
 * @author OceanStar
 * @create 2022-06-20 15:59
 */
public class CommonUtils {


    /**
     *
     * 获取入库台账的状态
     * @param state
     * @return
     */
    public static String getState(String state) {
//        状态: 新增(-1),已打印标签(0),入库(1),出库(2)
//        [ "新增","打印","已入库","已出库","已删除" ];
        String rest = "新增";
        if ("-1".equals(state)) {
            rest = "新增";
        } else if ("0".equals(state)) {
            rest = "已打印";
        } else if ("1".equals(state)) {
            rest = "已入库";
        } else if ("2".equals(state)) {
            rest = "已出库";
        } else if ("9".equals(state)) {
            rest = "删除";
        }
        return rest;
    }

/*
    public static void showTotal(Context context, String message,Integer backColor ){
        if(backColor == null){
            backColor = R.color.orange ;
        }
        Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
        LinearLayout layout = (LinearLayout) toast.getView();
        //设置背景 我这里设置的是纯颜色 可以设置任何资源文件
        layout.setBackgroundResource(backColor);
        layout.setPadding(11,3,11,3);
        //获取Toast默认文字显示ID
        TextView tv = (TextView) layout.getChildAt(0);
        //设置字体大小
        tv.setTextSize(22);
        //设置字体颜色
        tv.setTextColor(Color.WHITE);
        //Toast显示的位置
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }
    public static void showTotal( String message ){
        Toast toast = Toast.makeText(App.getContext(), message, Toast.LENGTH_SHORT);
        LinearLayout layout = (LinearLayout) toast.getView();
        //设置背景 我这里设置的是纯颜色 可以设置任何资源文件
        layout.setBackgroundResource(R.color.orange);
        layout.setPadding(11,3,11,3);
        //获取Toast默认文字显示ID
        TextView tv = (TextView) layout.getChildAt(0);
        //设置字体大小
        tv.setTextSize(22);
        //设置字体颜色
        tv.setTextColor(Color.WHITE);
        //Toast显示的位置
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }*/


    public  static String getIDByUrl(String url) {
        String id = "";
        if (StringUtils.isNotBlank(url) && url.indexOf("?sid=") >= 0) {
            String[] split = url.split("\\?sid=");
            id = split[1];
        } else if (StringUtils.isNotBlank(url) && url.indexOf("?sid=") < 0) {
            id = url;
        }
        return id;
    }
}
